package com.qf.domain;

import java.util.List;

/**
 * 【分页实体类】
 * pageNum页码   pageSize:页大小， totaSize:总数据个数
 *  pageConut:总页数  data:数据，  startPage:开始页码，
 *  endPage:结束页码
 */
public class PageBean<T> {
    //页码
     private int pageNum;
     //页大小(每页有多少数据)
     private int pageSize;
     //总数据个数
     private long totaSize;
     //总页数
    private int pageConut;
    //数据
    private List<T> data;
    //开始页
    private int startPage;
    //结束页码
    private int endPage;

    public PageBean() {
    }

    public PageBean(int pageNum, int pageSize, long totaSize, List<T> data) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totaSize = totaSize;
        this.data = data;
        //计算总页数
        this.pageConut = (int) (totaSize%pageSize==0?totaSize/pageSize:totaSize/pageSize+1);
        //1.正常情况下
        this.startPage = this.pageNum-4;
        this.endPage = this.pageNum+4;
        //2.当页码小于等于五时
        if (this.pageNum<=5){
            this.startPage = 1;
            this.endPage = 10;
        }
        //3.当页面大于总页码pageCount-5时
        if (this.pageNum>=this.pageConut-5){
            this.startPage = this.pageConut-9;
            this.endPage = this.pageConut;//此时结束页就等于总页数
        }
        //4.总页码不足10页
        if (this.pageConut<=10){
            this.startPage = 1;
            this.endPage = this.pageConut;
        }
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotaSize() {
        return totaSize;
    }

    public void setTotaSize(long totaSize) {
        this.totaSize = totaSize;
    }

    public int getPageConut() {
        return pageConut;
    }

    public void setPageConut(int pageConut) {
        this.pageConut = pageConut;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", totaSize=" + totaSize +
                ", pageConut=" + pageConut +
                ", data=" + data +
                ", startPage=" + startPage +
                ", endPage=" + endPage +
                '}';
    }
}
